package my.sorter.controller;

import com.google.common.base.Preconditions;
import com.google.j2objc.annotations.AutoreleasePool;
import my.sorter.bean.LoginBean;
import my.sorter.bean.StaffSecurityInfo;
import my.sorter.dao.model.Staff;
import my.sorter.service.SecurityService;
import my.sorter.service.SystemService;
import my.sorter.translator.out.MyMessage;
import my.sorter.utils.DateUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresGuest;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.tools.tree.PositiveExpression;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Currency;

@Controller
//@EnableAutoConfiguration
@SuppressWarnings("unused")
public class StarterController {
    @Resource
    private SystemService systemService;
    @Autowired
    private SecurityService securityService;
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @RequiresAuthentication
    @RequestMapping(value = "/hello", method = RequestMethod.POST)
    @ResponseBody
    Object home() throws Exception {
        LoginBean bean = systemService.consumerLogin(new LoginBean());
        StaffSecurityInfo staffSecurityInfo = securityService.getSecurityInfo(000001);
        redisTemplate.opsForValue().set("aaa", "111");
        if ("111".equals(redisTemplate.opsForValue().get("aaa"))) {
            return staffSecurityInfo;
        } else {
            throw new Exception("not got redis");
        }

//        return bean.isSuccess();
    }

    @RequestMapping(value = "/response", method = RequestMethod.GET)
    @ResponseBody
    String myResponse() throws JSONException {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", "error");
        jsonObject.put("message", "请先登入");
        jsonObject.put("time", DateUtils.nowDateToFormattedString());
        return jsonObject.toString();
    }


}
